package com.csx.governance.traffic.adapter.outbound;

import com.csx.governance.traffic.core.context.TrafficMessage;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerRequest;

/**
 * @author cuisongxu
 * @date 2023/4/2 11:58
 */
public class TrafficLoadBalancerRequest<T> implements LoadBalancerRequest<T> {

    private final TrafficMessage request;

    private final LoadBalancerRequest<T> delegate;

    public TrafficLoadBalancerRequest(TrafficMessage request, LoadBalancerRequest<T> delegate) {
        this.request = request;
        this.delegate = delegate;
    }

    @Override
    public T apply(ServiceInstance instance) throws Exception {
        return delegate.apply(instance);
    }

    public TrafficMessage getRequest() {
        return request;
    }

    public LoadBalancerRequest<T> getDelegate() {
        return delegate;
    }
}
